package managedbean.CRM.Discount;

import entity.CRM.Discount;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import session.stateless.CRM.DiscountBeanLocal;

@ManagedBean
@ViewScoped
public class DeleteDiscountManagerBean implements Serializable{
    @EJB
    private DiscountBeanLocal discountBeanLocal;
    private Discount discountToDelete;
    private String statusMessage;

    public Discount getDiscountToDelete() {
        return discountToDelete;
    }
    public void setDiscountToDelete(Discount discountToDelete) {
        this.discountToDelete = discountToDelete;
    }

    public String getStatusMessage() {
        return statusMessage;
    }
    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
    
    public DeleteDiscountManagerBean() {}
    
    public void initView(PhaseEvent event){
        if (discountToDelete ==null)
        {
            discountToDelete = (Discount) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("selectedDiscount");
        }
    }
    
    public void deleteDiscount(ActionEvent event){
        discountBeanLocal.deleteDiscount(discountToDelete.getDiscountId());
        statusMessage = "Discount Deleted Successfully"; 
 
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,  "Delete Discount Result: " +statusMessage+"", "")); 
    }   
    
}